import { ResPage, Substation } from "@/api/interface/index";
import { SUBSTATION } from "@/api/config/servicePort";
import taskStatistics from "@/assets/json/taskStatistics.json";
import http from "@/api";

// 获取任务单列表
export const getTaskOrderList = (params: Substation.ReqTaskOrderParams) => {
  return http.post<ResPage<Substation.ResTaskOrderList>>(SUBSTATION + `/task/page`, params);
};

// 填写回执
export const editTaskOrder = (params: { taskId: string; customSatisfaction: number; customEvaluation: string }) => {
  return http.post(SUBSTATION + `/task/receipt`, params);
};

// 为任务单分配配送员
export const assignTaskOrder = (params: { taskId: string; courierInfo: { courierId: number; courierName: string } }) => {
  return http.post(SUBSTATION + `/task/assign`, params);
};

// 导出任务单数据
export const exportTaskOrderInfo = (params: Substation.ReqTaskOrderParams) => {
  return http.download(SUBSTATION + `/task/export`, params);
};

// 获取缴款单列表
export const getPaymentList = (params: Substation.ReqPaymentParams) => {
  return http.post<ResPage<Substation.ResPaymentList>>(SUBSTATION + `/payment/page`, params);
};

// 获取分站信息
export const getSubstationInfo = (params: { substationId: number }) => {
  return http.post<Substation.SubstationInfo>(SUBSTATION + `/get`, params);
};

// 获取分站列表
export const getSubstationList = (params: Substation.ReqSubstationParams) => {
  return http.post<ResPage<Substation.ResSubstationList>>(SUBSTATION + `/page`, params);
};

// 获取分站列表
export const addSubstation = (params: Substation.SubstationInfo) => {
  return http.post(SUBSTATION + `/create`, params);
};

// 获取分站列表（名称）
export const getSubstationNameList = () => {
  return http.get<Substation.ResSubstationList[]>(SUBSTATION + `/list`);
};

// 统计一周内任务单类型和任务单状态
export const getTaskStatistics = (params: { substationId: number }): Substation.ResTaskOrderStatistics[] => {
  console.log(params);
  // return http.get<Substation.ResTaskOrderStatistics[]>(SUBSTATION + `/task/statistics`);
  return taskStatistics.data as unknown as Substation.ResTaskOrderStatistics[];
};

////////////////////////////////////////////////////////

// 修改分站信息
export const editSubstationName = (params: { substationName: string }) => {
  return http.post(SUBSTATION + `/edit`, params);
};

// // 编辑任务单状态
// export const editTaskOrderStatus = (params: { taskId: string; taskStatus: number }) => {
//   return http.post(SUBSTATION + `/task/editStatus`, params);
// };
